package android.slc.appbase.utils;

public class ClickCountProxy {
    public static final int DEF_VALID_INTERVAL = 512;
    public static final int DEF_EXECUTE_COUNT = 5;
    private int validInterval = DEF_VALID_INTERVAL;
    private int executeCount = DEF_EXECUTE_COUNT;
    private long preCallTime = 0L;
    private int currentClickCount = 0;
    private OnExecuteListener onExecuteListener;

    public int getValidInterval() {
        return validInterval;
    }

    public void setValidInterval(int validInterval) {
        this.validInterval = validInterval;
    }

    public int getExecuteCount() {
        return executeCount;
    }

    public void setExecuteCount(int executeCount) {
        this.executeCount = executeCount;
    }

    public OnExecuteListener getOnExecuteListener() {
        return onExecuteListener;
    }

    public void setOnExecuteListener(OnExecuteListener onExecuteListener) {
        this.onExecuteListener = onExecuteListener;
    }

    public void call() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - this.preCallTime < this.validInterval) {
            this.currentClickCount++;
            if (this.currentClickCount == this.executeCount) {
                this.currentClickCount = 0;
                //启动
                this.onExecuteListener.onExecute();
            }
        } else {
            this.currentClickCount = 1;
        }
        this.preCallTime = currentTime;
    }

    public interface OnExecuteListener {
        void onExecute();
    }
}
